Skip to content

feat(plugins): add document format registration ABI#941

Open
mimeding wants to merge 1 commit into
osaurus-ai:mainfrom
mimeding:feat/plugin-host-v2-document-adapters
Open

feat(plugins): add document format registration ABI#941
mimeding wants to merge 1 commit into
osaurus-ai:mainfrom
mimeding:feat/plugin-host-v2-document-adapters

Conversation

@mimeding
Copy link
Copy Markdown
Contributor

@mimeding mimeding commented Apr 24, 2026

Summary

This re-issues PR #941 as a focused one-commit branch on current origin/main (9e5c8bf0). The old stacked document/PPTX context has been dropped; this PR is only the plugin document-format registration surface.

What changed

  • Adds ABI v7 trailing host API fields: register_parser, register_emitter, and unregister_format.
  • Wires host-side trampolines that register plugin-owned parsers/emitters through PluginDocumentRegistry.
  • Adds plugin-backed DocumentFormatAdapter / DocumentFormatEmitter shims that invoke the loaded plugin route handler.
  • Cleans up plugin-owned document formats on plugin unload.
  • Updates ABI docs, host API docs, frozen layout checks, and host API tests for v7.

Validation

  • swift test --package-path Packages/OsaurusCore --filter 'PluginDocumentRegistry|PluginHostAPI|PluginHostAPIStructLayout|PluginHostFreeString|PluginCompleteCancel' passed, 86 tests.
  • git diff --check origin/main...HEAD passed.
  • swiftlint lint --strict --config .swiftlint.yml passed on the two new plugin document shim files.
  • Full-file strict SwiftLint on all touched Swift files still reports existing violations in large preexisting plugin files (PluginManager.swift, ExternalPlugin.swift, PluginHostAPI.swift); those violations are outside the added hunks.

Non-scope

  • No in-tree PPTX/POTX adapter or emitter.
  • No plugin marketplace/release changes.
  • No richer plugin response schema beyond text fallback.

@mimeding mimeding force-pushed the feat/plugin-host-v2-document-adapters branch 3 times, most recently from 89c5ddf to 73a299c Compare April 28, 2026 22:07
@mimeding mimeding force-pushed the feat/plugin-host-v2-document-adapters branch from 73a299c to 575de84 Compare May 1, 2026 02:54
@mimeding mimeding marked this pull request as ready for review May 1, 2026 03:22
@mimeding mimeding force-pushed the feat/plugin-host-v2-document-adapters branch 2 times, most recently from 3d87e66 to 00343dc Compare May 1, 2026 21:18
@mimeding mimeding changed the title feat(plugins): document format register_parser/register_emitter surface feat(documents): plugin format surface plus PPTX/POTX adapter May 3, 2026
@mimeding mimeding force-pushed the feat/plugin-host-v2-document-adapters branch from 1e7a778 to 75bca63 Compare May 3, 2026 23:58
@mimeding mimeding marked this pull request as draft May 10, 2026 14:57
Adds the host-side bridge between the plugin ABI and the document
format registry so plugin-provided parsers and emitters plug into
DocumentFormatRegistry the same way the in-tree adapters do. A plugin
that registers a parser through this surface ends up as a regular
adapter consumers can look up via registry.adapter(for:) — no plugin-
specific branch in the consumer.

The plugin-side invocation (how a plugin's invoke pointer gets wired
back into the shim adapter) is structured around a PluginDocumentInvoker
protocol so the host-to-plugin callback is a single seam. This PR
wires the Swift side end-to-end and tests it with a fake invoker;
the PluginManager plumbing that threads each plugin's real invoke
pointer into PluginDocumentInvoker lands with a follow-up since it
needs access to PluginManager internals.

- osaurus_plugin.h: adds osr_register_parser_fn / register_emitter_fn /
  unregister_format_fn signatures and the trailing struct fields,
  with full request/response JSON contract documented inline.
  Trailing fields — older plugins compiled against the v2 layout
  pre-this-PR keep loading because the host allocates the struct and
  zero-inits the new tail.
- PluginBackedDocumentAdapter.swift: Swift shims implementing
  DocumentFormatAdapter and DocumentFormatEmitter by forwarding to a
  plugin via PluginDocumentInvoker.invoke(type:id:payload:). Surfaces
  only the textFallback representation today; richer representations
  (Workbook, PDFDocumentRepresentation) come with a response-schema
  extension once a first plugin needs them.
- PluginDocumentRegistry.swift: owns format_id -> plugin_id
  ownership so one plugin can't unregister another's format (or
  overwrite an in-tree built-in). Returns JSON envelopes matching the
  C-header contract.
- Tests: 8 scenarios covering happy-path registration, adapter →
  plugin invocation threading, plugin error propagation, emitter
  routing, another-plugin-cannot-overwrite, reject-unregister-by-
  other, unregisterAll teardown on plugin unload, and malformed-JSON
  rejection.
@mimeding mimeding force-pushed the feat/plugin-host-v2-document-adapters branch from 75bca63 to fd6a6e0 Compare May 17, 2026 22:58
@mimeding mimeding changed the title feat(documents): plugin format surface plus PPTX/POTX adapter feat(plugins): add document format registration ABI May 17, 2026
@mimeding mimeding marked this pull request as ready for review May 17, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant